<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<script src="${pageContext.request.contextPath}/dwz/js/dwz.database.js" type="text/javascript"></script>
<script type="text/javascript">
function saveout(){
	var uuidout = document.getElementsByName("orgLookup.uuid");
	var listout = {};
	var inNumout = document.getElementsByName("num");
	var devnum = document.getElementsByName("orgLookup.devNum");
	var outType = $('input[name="outType"]:checked').val();
	var schoolNames=document.getElementsByName("orgLookup.sclName");
	var counts=0;
	for (var j = 1; j < uuidout.length; j++) {
		for(var x=j+1;x<uuidout.length;x++){
			if(uuidout[j].value==uuidout[x].value){
				counts++;
			}
			
		}
		if(counts>0){
			alertMsg.error("不能添加重复条目！");
			return false;
		}
		
		
		if (uuidout[j].value == "") {
			alertMsg.error("请添加明细！");
			return false;
		}
		else{
			if (inNumout[j].value == "") {
				alertMsg.error("入库数量不能为空！");
				inNumout[j].focus();
				return false;
			}else{
				var reg = /^[0-9]*[1-9][0-9]*$/;
				if (!reg.test(inNumout[j].value)) {
					alertMsg.error("必须输入大于0的正整数！");
					inNumout[j].value = "";
					inNumout[j].focus();
					return false;
				}
				 if(parseInt(inNumout[j].value)>parseInt(devnum[j].value)){
					alertMsg.error("出库数量不能大于库存！");
					inNumout[j].value = "";
					inNumout[j].focus();
					return false;
				} 
				
				
				}
			if(outType=="1"){
				if(schoolNames[j].value==""||typeof(schoolNames[j].value)==undefined){
					alertMsg.error("领用必须选择学校！");
					return false;
				}
			}
			listout[j-1] = inNumout[j].value + "," + uuidout[j].value+","+schoolNames[j].value;
	}
	}
				var describ=$("#describ").val();
				var userName=$("#userName").val();
				
				var user=document.getElementsByName("userId");
				var userIds="";
				for(var k=1;k<user.length;k++){
					userIds=user[k].value;
				}
				var  url="stock_stockDevOut.action";
			  data={
					  "dataList":listout,
					  "stockDevOut.describ":describ,
					  "stockDevOut.inputer":userName,
					  "stockDevOut.outType":outType,
					  "stockDevOut.inputId":userIds
			  },
			  $.ajax({ 
				  url: url, 
				  type:"post",
				  data :data,
				  dataType:"json",
				  success: function(message){
			      if(message!=""){
			    	  alertMsg.correct("出库申请成功！");
			    	  $("#reMoveList").empty();
			      } 
			      }});
			  
}
function selScl(){
  	var outType=$('input[name="outType"]:checked').val();
	
	if(outType=="2"){
		alertMsg.error("报损无需选择学校！");
		return;
	}else{
		return;
	}
	
}
</script>
<style>
<!--
.searchContent td label{
width:50px;
}
-->
</style>
<%--dwz分页查询 隐藏传值表单  begin --%>
<form id="pagerForm" method="post" action="#rel#">
	<input type="hidden" name="pageNum" value="${currentPage }" /> 
	<input type="hidden" name="numPerPage" value="${numPerPage}" /> 
	<input type="hidden" name="orderField" value="${param.orderField}" /> 
	<input type="hidden" name="orderDirection" value="${param.orderDirection}" />
</form>
<%--dwz分页查询 隐藏传值表单  end --%>
<%--页头 检索条件区域 begin --%>
<div class="pageHeader">
<form rel="pagerForm" onsubmit="return navTabSearch(this);"	action="stock_listStockDev.action" method="post">
		<div class="searchBar">
			<table class="searchContent">
				       <tr>
				       <td>
				         申请人：
				       </td>
				       <td>
				       <input value="${session.currentUser.userRole.usrName }" id="userName" type="text" readonly="readonly"/>
				       <input value="${session.currentUser.userRole.usrId }" id="userId" name="userId" type="hidden"/><!-- 登陆工号 -->
				       </td>
				       <td>
				       <input type="radio" value="1" name="outType" checked="checked" />领用   &nbsp;&nbsp;&nbsp; 
				       <input type="radio" value="2" name="outType"/>报损
				       </td>
				  </tr>
				  <tr>
				      <td>备注：</td>
				      <td colspan="2">
				      <textarea rows="2" cols="30" id="describ"></textarea>
				      
				      </td>
				  </tr>
				</table>
		</div>
	</form>
</div>
<%--页头 检索条件区域 end --%>
<%--内容展示区域 begin --%>
<div class="pageContent">
	<%-- 工具栏  begin --%>
	<div class="panelBar">
		<ul class="toolBar">
			<li >
				<a id="link_stockdevice_out" class="add" href="javascript:void(0)" onclick=""><span>新建出库单</span></a>
				<input type="hidden" id="db_btn_link_id" value="link_stockdevice_out">
			</li>
			<li><a class="add" href="javascript:void(0)" onclick="saveout()"><span>提交申请</span></a></li>
		</ul>
	</div>
	<%-- 工具栏 end  --%>
	
			
	<%-- 分页table列表 begin --%>
	<table class="list nowrap itemDetail" addButton="新建出库单" width="100%">
		<thead>
			<tr>
				<th type="readonly" id="uuid" name="orgLookup.uuid"
					suggestFields="orgNum,uuid">序列号</th>
				<th type="readonly" id="devName" name="orgLookup.devName" value=""
					suggestFields="orgNum,orgName">设备名称</th>
				<th type="readonly" id="devUnit" name="orgLookup.devUnit" value=""
					suggestFields="orgNum,devUnit">设备单位</th>
				<th type="text" name="num" id="num">设备数量</th>
				<th type="readonly" id="devVer" name="orgLookup.devVer" value=""
					suggestFields="orgNum,devVer">设备版本</th>
				<th type="readonly" id="devSupplierName" name="orgLookup.devSupplierName" value=""
					suggestFields="orgNum,devUnit">设备供应商</th>
				<th type="readonly" id="devNum" name="orgLookup.devNum" value=""
					suggestFields="orgNum,devNum">库存数量</th>
				<th type="readonly" id="describe" name="orgLookup.describe" value=""
					suggestFields="orgNum,describe">设备描述</th>
				<th type="lookup1" name="orgLookup.sclName" lookupGroup="orgLookup" 
					lookupUrl="school_lookup.action" 
					suggestFields="orgNum,sclName" postField="keywords" size="12" >领用学校</th>
				<th type="lookup" name="items[#index#].org.orgName"
					lookupGroup="orgLookup" lookupUrl="stock_stockOutDev.action">选择设备</th>
				<th type="del" width="60">操作</th>

			</tr>
		</thead>		
		<tbody id="reMoveList"></tbody>		
		</table>
		
	<%-- 分页table列表 end --%>
	
	<%--分页信息区 begin--%>
	<%--分页信息区 end--%>
</div>